
// set function parseTime,formatTime to filter
// export { parseTime, formatTime } from '@/utils'

function pluralize(time, label) {
  if (time === 1) {
    return time + label
  }
  return time + label + 's'
}

export function timeAgo(time) {
  const between = Date.now() / 1000 - Number(time)
  if (between < 3600) {
    return pluralize(~~(between / 60), ' minute')
  } else if (between < 86400) {
    return pluralize(~~(between / 3600), ' hour')
  } else {
    return pluralize(~~(between / 86400), ' day')
  }
}

/* 数字 格式化*/
export function numberFormatter(num, digits) {
  const si = [
    { value: 1E18, symbol: 'E' },
    { value: 1E15, symbol: 'P' },
    { value: 1E12, symbol: 'T' },
    { value: 1E9, symbol: 'G' },
    { value: 1E6, symbol: 'M' },
    { value: 1E3, symbol: 'k' }
  ]
  for (let i = 0; i < si.length; i++) {
    if (num >= si[i].value) {
      return (num / si[i].value + 0.1).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].symbol
    }
  }
  return num.toString()
}

export function toThousandFilter(num) {
  return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}

export function ellipsis(val, num) {
  if (val.length > num) {
    return val.slice(0, num + 1) + '...'
  }
  return val
}
export function lineFeed(value) {
  console.log('date', value.replace(' ', '\r\n'))
  return value.replace(' ', '\n')
}

// 时间格式化
export function editTime(time) {
  var data = new Date(time)
  var y = data.getFullYear() + '-'
  var m = (data.getMonth() + 1) > 0 ? (data.getMonth() + 1) + '-' : '0' + (data.getMonth() + 1) + '-'
  var d = data.getDate() + ' '
  var h = data.getHours() + ':'
  var minu = data.getMinutes() + ':'
  var s = data.getSeconds()
  return y + m + d + h + minu + s
}

// 是否
export function whether(num) {
  if (num == 1) {
    return '是'
  } else if (num == 2) {
    return '否'
  }
}

// 应急专家出勤率
// export function topbom(data) {
//   if (data == 'high') {
//     return '高'
//   } else if (data == 'low') {
//     return '低'
//   }
// }

// 救援队类型
export function resType(num) {
  // if (num == '1') {
  //   return '综合'
  // } else if (num == '2') {
  //   return '专业'
  // } else if (num == '3') {
  //   return '社会'
  // }
  let type = ''
  switch (num) {
    case '1':
      type = '综合'
      break
    case '2':
      type = '专业'
      break
    case '3':
      type = '社会'
      break
    default:
      type = ''
  }
  return type
}

// 应急专家所在地
export function areaType(num) {
  let area = ''
  switch (num) {
    case '1':
      area = '本市'
      break
    case '2':
      area = '本省外市'
      break
    case '3':
      area = '外省'
      break
    default:
      area = ''
  }
  return area
}

